package nayasis.common.executor;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import nayasis.common.log.NLogger;

public class ProcessThread extends Thread {

	private InputStream inputStream;

	/**
	 * 생성자
	 *
	 * @param inputStream Process 에서 출력되는 메세지 Stream 객체
	 */
	public ProcessThread( InputStream inputStream ) {

		this.inputStream = inputStream;

	}

	/* (non-Javadoc)
	 * @see java.lang.Thread#run()
	 */
	public void run() {

		try {

			pullStreamString( inputStream );

		} catch ( Exception e ) {
			NLogger.err.println( e );

		} finally {
			try { if (inputStream != null) inputStream.close(); } catch (IOException e) {}
		}
	}

	/**
	 * 입력 Stream을 그냥 쭉 뽑아주는 역할만 수행한다.
	 * 
	 * @param inputStream 입력 Stream
	 */
	private void pullStreamString( InputStream inputStream ) {

		try (
			BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream) );
		) {

			while ( reader.readLine() != null ) {}

		} catch ( IOException e ) {

			return;

		}			

	}
	
}
